import request from '@/utils/request'

/* 获取左侧拖拽列表的数据/和子节点的数据 */
export function postQueryPageList(data) {
  return request({
    url: `/plm-sys/objectFolder/queryPageList`,
    method: 'post',
    data: data
  })
}
// 左侧 拖动文档或者文件夹，接口
export function putUpdate(data) {
  return request({
    url: '/plm-sys/objectFolder/update',
    method: 'put',
    data: data
  })
}

// 附件列表接口
export function postFileQueryPageList(id) {
  return request({
    url: `/plm-sys/objectAttachment/queryPageList`,
    method: 'post',
    data: {
      pageNo: 1,
      pageSize: 1000,
      t: {
        objectId: id
      }
    }
  })
}
// 附件预览接口
export function postPlmfile(data, responseType) {
  return request({
    url: `/plm-sys/api/plmfile`,
    headers: { 'Content-type': 'application/x-www-form-urlencoded' },
    responseType: responseType,
    method: 'post',
    data
  })
}

// 附件列表
export function getFileList(id) {
  return request({
    url: `/plm-sys/sys/list/{${id}}`,
    method: 'get'
  })
}
// 批量上传附件
export function postBatchUpload(data) {
  return request({
    url: `/plm-sys/sys/batchUpload`,
    method: 'post',
    data: data
  })
}
// 单个上传
export function postUpload(data, file) {
  return request({
    url: `/plm-sys/objectAttachment/upload`,
    method: 'post',
    onUploadProgress: (progressEvent) => {
      const num = progressEvent.loaded / progressEvent.total * 100 | 0 // 百分比
      file.onProgress({ percent: num }) // 进度条
    },
    data: data
  })
}
// 确认绑定上传附件
export function postFileAdd(data) {
  return request({
    url: `/plm-sys/objectAttachment/add`,
    method: 'post',
    data: data
  })
}

// 基本属性接口
export function getQueryBaseAttribute(id) {
  return request({
    url: `/plm-sys/objectInstance/queryBaseAttribute?id=${id}`,
    method: 'get'
  })
}
// 根据列表code获取列表值的下拉数据
export function postQueryListSelectData(code) {
  return request({
    url: `/plm-sys/api/sysDict/queryListSelectData?code=${code}`,
    method: 'post'
  })
}

// 对象的属性保存/修改接口
export function putBAUpdate(data) {
  return request({
    url: '/plm-sys/objectInstance/update',
    method: 'put',
    data: data
  })
}
// 根据id查看(对象实例)数据 \ 基本信息接口
export function getViewObjectInstanceByList(id) {
  return request({
    url: `/plm-sys/objectInstance/viewObjectInstanceByList?id=${id}`,
    method: 'get'
  })
}

// 附件模块 删除接口
export function deleteDels(data) {
  return request({
    url: '/plm-sys/objectAttachment/dels',
    method: 'delete',
    data: data
  })
}

// 附件模块 签出接口
export function putCheckOutfile(id) {
  return request({
    url: `/plm-sys/objectAttachment/checkOutfile?id=${id}`,
    method: 'put'
  })
}
// 附件模块 签入接口
export function putCheckInfile(data) {
  return request({
    url: '/plm-sys/objectAttachment/checkInfile',
    method: 'put',
    data: data
  })
}
// 附件模块 下载接口
export function postDown(ids) {
  return request({
    url: `/plm-sys/objectAttachment/down`,
    method: 'post',
    responseType: 'blob',
    data: ids
  })
}

// 附件模块 粘贴接口
export function postCopy(data) {
  return request({
    url: `/plm-sys/objectAttachment/copy?fromfileId=${data.fromfileId}&toObjectInsId=${data.toObjectInsId}`,
    method: 'post'
  })
}

// 附件模块 取消签出接口
export function putCancelCheckOutfile(id) {
  return request({
    url: `/plm-sys/objectAttachment/cancelCheckOutfile?id=${id}`,
    method: 'put'
  })
}
// 文件信息 删除
export function postDel(queryVos) {
  return request({
    url: `/plm-sys/objectFolder/del`,
    method: 'post',
    data: {
      queryVos: queryVos
    }
  })
}
// 文件信息 搜索文档
export function getObjectInsList(data) {
  return request({
    url: `/plm-sys/objectInstance/getObjectInsList?workspaceId=${data.workspaceId}&objectType=${data.objectType}&search=${data.search}`,
    method: 'get'
  })
}

// 创建文件夹
export function postAdd(data) {
  return request({
    url: `/plm-sys/objectFolder/add`,
    method: 'post',
    data: data
  })
}

// 另存文件
export function getViewObjectInstanceByIdCopy(id) {
  return request({
    url: `/plm-sys/objectInstance/viewObjectInstanceByIdCopy?id=${id}`,
    method: 'get'
  })
}
